import cv2
import numpy as np
def _corner_filling(img):
    mask = np.zeros_like(img)
    # mask_down = np.zeros_like(img)
    # mask[img != 0] = 1
    # 筛选mask
    [r, c] = img.shape
    img_up = img[0:int(r / 10),...]
    img_down = img[int(9*r/10):-1,...]
    mask_up = np.zeros_like(img_up)
    mask_down = np.zeros_like(img_down)

    mask_up[img_up < np.mean(img_up)*0.4] = 1
    mask_down[img_down < np.mean(img_down) * 0.4] = 1

    # open-process
    mask_up = cv2.dilate(mask_up, np.ones([7, 7]))
    mask_up = cv2.erode(mask_up, np.ones([3, 3]))

    mask_down = cv2.dilate(mask_down, np.ones([7, 7]))
    mask_down = cv2.erode(mask_down, np.ones([3, 3]))


    mask[0:int(r / 10),...] = mask_up
    mask[int(9*r/10):-1,...] = mask_down


    img_downsample = cv2.resize(img,[4,16])
    img_upsample = cv2.resize(img_downsample, mask.shape[::-1])
    # img_upsample[mask != 0] = img[mask != 0]

    img[mask!=0] = img_upsample[mask!=0]
    return img